package utils.encoding;
import java.io.UnsupportedEncodingException;
import org.apache.commons.lang.StringUtils;

/**
 * @author Terrence
 * @time 2012-12-26
 */
public class StringEncodingConvert {
	private final static String Encoding_ISO_8859_1 = "ISO-8859-1";
	private final static String Encoding_GBK = "GBK";
	private final static String Encoding_UTF_8 = "UTF-8";
	
	public static String ISOtoGBK(String source) {
		return convert(source,Encoding_ISO_8859_1,Encoding_GBK);
	}
	public static String ISOtoUTF_8(String source) {
		return convert(source,Encoding_ISO_8859_1,Encoding_UTF_8);
	}
	public static String GBKtoUTF_8(String source){
		return convert(source,Encoding_GBK,Encoding_UTF_8);
	}
	public static String UTF_8toGBK(String source){
		return convert(source,Encoding_UTF_8,Encoding_GBK);
	}
	
	private static String convert(String source,String fromEncoding ,String toEncoding){
		try {
			return StringUtils.isBlank(source) ? null : new String(source.getBytes(fromEncoding),toEncoding);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static void main(String[] args) {
	}
}
